<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <!-- 失去焦点时候绑定数据 -->
        <input type="text" v-model.lazy="msg"> {{msg}} {{num}}
    </div>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                msg: "",
                num: 10
            },
            methods: {},
            mounted() {
                // 该方法是通过$once这个事件侦听器在定义完定时器之后的位置来清除定时器
                const timer = setInterval(() => {
                    console.log('1')
                }, 1000)
                this.$once('hook:updated', () => {
                    clearInterval(timer)
                })
            },
            updated() {
                console.log('数据更新')
            },
        })
    </script>
</body>

</html>